<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php  $_results = $this->getTrackingInfo() ?>
<div class="page-title title-buttons">
    <h1><?php echo $this->__('Tracking Information'); ?></h1>
    <button class="button" onclick="window.close(); window.opener.focus();"><span><span><?php echo $this->__('Close Window') ?></span></span></button>
</div>
<?php if(sizeof($_results)>0): ?>
<?php foreach($_results as $shipid => $_result): ?>
    <?php if($shipid): ?>
    <h2><?php echo $this->__('Shipment #').$shipid; ?></h2>
    <?php endif; ?>
    <?php if(sizeof($_result)>0): ?>
        <?php $rowCount = sizeof($_result); $counter = 1; ?>
        <?php foreach($_result as $track): ?>
        <table class="tracking-table-popup">
            <col width="15%" />
            <col />
            <tbody>
                <?php if(is_object($track)): ?>
                <tr>
                    <th><?php echo $this->__('Tracking Number:'); ?></th>
                    <td><?php echo $track->getTracking(); ?></td>
                </tr>
                <?php if ($track->getCarrierTitle()): ?>
                <tr>
                    <th><?php echo $this->__('Carrier:'); ?></th>
                    <td><?php echo $track->getCarrierTitle(); ?></td>
                </tr>
                <?php endif; ?>
                <?php if($track->getErrorMessage()): ?>
                <tr>
                    <th><?php echo $this->__('Error:'); ?></th>
                    <td class="error"><?php echo $this->__('Tracking information is currently not available. Please '); if ($this->getContactUsEnabled()) : ?><a href="<?php echo $this->getContactUs() ?>" onclick="this.target='_blank'"><?php echo $this->__('contact us') ?></a><?php echo $this->__(' for more information or '); endif; echo $this->__('email us at '); ?><a href="mailto:<?php echo $this->getStoreSupportEmail() ?>"><?php echo $this->getStoreSupportEmail() ?></a></td>
                </tr>
                <?php elseif($track->getTrackSummary()): ?>
                <tr>
                    <th><?php echo $this->__('Info:'); ?></th>
                    <td><?php echo $track->getTrackSummary(); ?></td>
                </tr>
                <?php elseif($track->getUrl()): ?>
                <tr>
                    <th><?php echo $this->__('Track:'); ?></th>
                    <td><a href="<?php echo $track->getUrl(); ?>" onclick="this.target='_blank'"><?php echo $track->getUrl(); ?></a></td>
                </tr>
                <?php else: ?>
                    <?php if ($track->getStatus()): ?>
                    <tr>
                        <th><?php echo $this->__('Status:'); ?></th>
                        <td><?php echo $track->getStatus(); ?></td>
                    </tr>
                    <?php endif; ?>

                    <?php if ($track->getDeliverydate()): ?>
                    <tr>
                        <th><?php echo $this->__('Delivered on:'); ?></th>
                        <td><?php echo $this->formatDeliveryDateTime($track->getDeliverydate(),$track->getDeliverytime()); ?></td>
                    </tr>
                    <?php endif; ?>

                    <?php if ($track->getSignedby()): ?>
                    <tr>
                        <th><?php echo $this->__('Signed by:'); ?></th>
                        <td><?php echo $track->getSignedby(); ?></td>
                    </tr>
                    <?php endif; ?>

                    <?php if ($track->getDeliveryLocation()): ?>
                    <tr>
                        <th><?php echo $this->__('Delivered to:'); ?></th>
                        <td><?php echo $track->getDeliveryLocation(); ?></td>
                    </tr>
                    <?php endif; ?>

                    <?php if ($track->getShippedDate()): ?>
                    <tr>
                        <th><?php echo $this->__('Shipped or billed on:'); ?></th>
                        <td><?php echo $track->getShippedDate(); ?></td>
                    </tr>
                    <?php endif; ?>

                    <?php if ($track->getService()): ?>
                    <tr>
                        <th><?php echo $this->__('Service Type:'); ?></th>
                        <td><?php echo $track->getService(); ?></td>
                    </tr>
                    <?php endif; ?>

                    <?php if ($track->getWeight()): ?>
                    <tr>
                        <th><?php echo $this->__('Weight:'); ?></th>
                        <td><?php echo $track->getWeight(); ?></td>
                    </tr>
                    <?php endif; ?>

                    <?php endif; ?>
                    <?php elseif(isset($track['title']) && isset($track['number']) && $track['number']): ?>
                    <!--if the tracking is custom value-->
                    <tr>
                        <th><?php echo ($track['title'] ? $this->escapeHtml($track['title']) : $this->__('N/A')); ?>:</th>
                        <td><?php echo (isset($track['number']) ? $this->escapeHtml($track['number']) : ''); ?></td>
                    </tr>
                    <?php endif; ?>
                    </tbody>
                </table>
                <div class="divider"></div>
                <?php if (is_object($track) && sizeof($track->getProgressdetail())>0): ?>
                <table class="data-table" id="track-history-table-<?php echo $track->getTracking(); ?>">
                    <col />
                    <col width="1" />
                    <col width="1" />
                    <col />
                    <thead>
                        <tr>
                            <th><?php echo $this->__('Location') ?></th>
                            <th><?php echo $this->__('Date') ?></th>
                            <th><?php echo $this->__('Local Time') ?></th>
                            <th><?php echo $this->__('Description') ?></th>
                        </tr>
                   </thead>
                   <tbody>
                   <?php foreach($track->getProgressdetail() as $_detail): ?>
                    <?php $_detailDate = (isset($_detail['deliverydate']) ? $this->formatDeliveryDate($_detail['deliverydate']) : '') ?>
                    <?php $_detailTime = (isset($_detail['deliverytime']) ? $this->formatDeliveryTime($_detail['deliverytime'], $_detailDate) : '') ?>
                        <tr>
                            <td><?php echo (isset($_detail['deliverylocation']) ? $_detail['deliverylocation'] : ''); ?></td>
                            <td><?php echo $_detailDate ?></td>
                            <td><?php echo $_detailTime ?></td>
                            <td><?php echo (isset($_detail['activity']) ? $_detail['activity'] : '') ?></td>
                        </tr>
                   <?php endforeach; ?>
                   </tbody>
                </table>
                <script type="text/javascript">decorateTable('track-history-table-<?php echo $track->getTracking(); ?>');</script>
                <?php endif; ?>
            <?php if($counter!=$rowCount): ?>
            <?php endif; ?>
            <?php $counter++; ?>
        <!--end for each tracking information-->
        <?php endforeach; ?>
    <?php else: ?>
        <p><?php echo $this->__('There is no tracking available for this shipment.'); ?></p>
    <?php endif; ?>

<?php endforeach; ?>
<?php else: ?>
    <div><?php echo $this->__('There is no tracking available.'); ?></div>
<?php endif; ?>
<div class="buttons-set">
    <button type="button" title="<?php echo $this->__('Close Window') ?>" class="button" onclick="window.close(); window.opener.focus();"><span><span><?php echo $this->__('Close Window') ?></span></span></button>
</div>
